package com.lhhu.demo.controller;

import com.lhhu.demo.bean.OrderMessage;
import com.lhhu.demo.config.LogAnnotation;
import com.lhhu.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther 虎
 * @Data 2021/3/23 17:55
 * @Version 1.0
 */
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/addOneOrder")
    public String addOneOrder(String orderOpenid, String orderBookId, String orderRecipient, String orderPhone , String orderAddress, int orderCounts,double orderMoney){
        OrderMessage orderMessage = new OrderMessage();
        orderMessage.setOrderOpenid(orderOpenid);
        orderMessage.setOrderBookId(orderBookId);
        orderMessage.setOrderRecipient(orderRecipient);
        orderMessage.setOrderPhone(orderPhone);
        orderMessage.setOrderAddress(orderAddress);
        orderMessage.setOrderCounts(orderCounts);
        orderMessage.setOrderMoney(orderMoney);
        orderMessage.setOrderStatus("待付款");
        System.out.println(orderMessage);
        return orderService.addOneOrder(orderMessage);
    }

    @GetMapping("/getAllOrderByStatus")
    public List<OrderMessage> getAllOrderByStatus(String openid,String orderStatus){
        return orderService.getAllOrderByStatus(openid,orderStatus);
    }

    @LogAnnotation(module = "订单管理模块",action = "配送完成")
    @PutMapping("/confirmOrder")
    public int confirmOrder(String codes, String orderId,String orderStatus){
        return orderService.confirmOrder(orderId,orderStatus);
    }

    @LogAnnotation(module = "订单管理模块",action = "支付成功")
    @GetMapping("/payMoney")
    public int payMoney(String orderId,String orderStatus){
        return orderService.confirmOrder(orderId,orderStatus);
    }

    @GetMapping("/getAllOrderByOrderId")
    public List<OrderMessage> getAllOrderByOrderId(String orderId,String orderStatus){
        return orderService.getAllOrderByOrderId(orderId,orderStatus);
    }

    @GetMapping("/getAllOrderByPhone")
    public List<OrderMessage> getAllOrderByPhone(String orderPhone,String orderStatus){
        return orderService.getAllOrderByPhone(orderPhone,orderStatus);
    }

    @GetMapping("/getAllOrderByTime")
    public List<OrderMessage> getAllOrderByTime(String begindate, String enddate,String orderStatus){
        return orderService.getAllOrderByTime(begindate, enddate, orderStatus);
    }

    @LogAnnotation(module = "订单管理模块",action = "删除订单")
    @GetMapping("/deleteOneOrder")
    public int deleteOneOrder(String orderId){
        return orderService.deleteOneOrder(orderId);
    }
}
